package 卖票;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SellTicketsLock  implements Runnable {
    private static int ticket = 100;
    private Lock lockk = new ReentrantLock();
    public void run() {
        while (true) {
            try {
                lockk.lock();
                if (ticket > 0) {
                    System.out.println(Thread.currentThread().getName() + "卖出第：" + ticket + "张票");
                    ticket--;
                    System.out.println("已售出");
                }
            }finally {
                lockk.unlock();

            }

        }
    }

}


